<?php
/**
 * Rooms Model for Room Booking Component
 * 
 * @version 1.0
 * @package    Joomla
 * @subpackage RoomBooking
 * @copyright (C) 2011 Giovanni Marzulli
 * @license		GNU/GPL
 */
 
// No direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.model' );
 
class RoomBookingModelRooms extends JModel
{
    
	/**
	 * Method to get rooms
	 * @return array Array of objects containing the data from the database
	 */
	function getRooms()
	{
		// Load the data
			$query = ' SELECT *  '
            		. ' FROM #__roombooking_rooms WHERE open = 1' ;
			$rooms = $this->_getList( $query );
			
		return $rooms;
	}
    
    /**
    * Gets the rooms of a building
    * @return array Array of objects containing the data from the database
    */
    function getRoomsOfBuilding($id_building)
    {
		$db =& JFactory::getDBO();
 
  		$query = 'SELECT r.id, r.name, r.floor, t.name as t_name, t.num_seats, t.cost FROM #__roombooking_rooms AS r LEFT JOIN #__roombooking_rooms_types AS t ON r.room_type_id = t.id WHERE open=1 AND id_building='.$id_building;
                
   		$rooms = $this->_getList( $query );

   		return $rooms;
    	
    }
    
}
